package com.listeningframework.boot.domains;

import java.util.List;

public class Domains {
    /**
     * 创建返回对象
     *
     * @param <T> 返回泛型
     * @return ResponseBodys
     */
    public static <T> ResponseBodys<T> newResponseBody() {
        return new ResponseBodys<T>();
    }

    /**
     * 失败返回
     *
     * @param message 错误描述
     * @param <T>     返回泛型
     * @return ResponseBodys
     */
    public static <T> ResponseBodys<T> responseBodyFail(String message) {
        ResponseBodys<T> result = newResponseBody();
        result.setMessage(message);
        result.setResponseFail();
        return result;
    }

    /**
     * ExtJsResponseBody success
     *
     * @param message 成功描述
     * @param <T>     返回泛型
     * @return ResponseBodys
     */
    public static <T> ResponseBodys<T> responseBodySuccess(String message) {
        ResponseBodys<T> result = newResponseBody();
        result.setResponseSuccess();
        return result;
    }

    /**
     * Response Body Success
     *
     * @param dataList   数据列表
     * @param totalCount 记录数
     * @param <T>        返回泛型
     * @return ResponseBodys
     */
    public static <T> ResponseBodys<T> responseBodySuccess(List<T> dataList, Integer totalCount) {
        ResponseBodys<T> result = newResponseBody();
        result.setResponseSuccess();
        result.setResults(totalCount);
        result.setRows(dataList);
        return result;
    }

}
